package kr.kosta.spring.aop.customer;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After; 
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; 
import org.aspectj.lang.annotation.Pointcut; 
import org.springframework.stereotype.Service;
 
@Service
@Aspect
public class LoggingAdvice {
 
    @Pointcut("execution(* kr.kosta.spring.aop.customer.service.CustomerServiceImpl.get*(..))")
     public void logging() {    }
      
    @Pointcut("execution(* kr.kosta.spring.aop.customer.service.CustomerServiceImpl.*List(..))")
     public void authentification() {}
      
    @Before("execution(* kr.kosta.spring.aop.customer.service.CustomerServiceImpl.get*(..))")
    public void before() {
         System.out.println("* before *");
    }
    
    @Around("authentification()")
    public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
    	
    	String signatureString = joinPoint.getSignature().toShortString();
    	
    	System.out.println("[공통기능]" + signatureString + " 시작");
    	long start = System.currentTimeMillis();
    	Object obj = joinPoint.proceed();
    	System.out.println("[공통기능]" + signatureString + " 끝");
    	long end = System.currentTimeMillis();
    	
    	System.out.println(signatureString + " 실행시간 : " + (end-start) + "ms");
    	
    	return obj;
    	
    }
     
    @After("execution(* kr.kosta.spring.aop.customer.service.CustomerServiceImpl.*List(..))")
    public void after() {
        System.out.println("* end *");
    }
     
}